package com.naiterui.ehp.bs.recommend.controller.inner;


import cn.hutool.core.bean.BeanUtil;
import com.naiterui.ehp.bp.bo.recommend.DrugRemindBO;
import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bp.support.exception.PublicService;
import com.naiterui.ehp.bp.support.exception.ResponseVO;
import com.naiterui.ehp.bs.recommend.exception.ExceptionCodes;
import com.naiterui.ehp.bs.recommend.service.IAssistService;
import com.naiterui.ehp.bs.recommend.vo.assist.DrugRemindVO;
import com.naiterui.ehp.bs.recommend.vo.assist.OrderParamVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author gaoliangliang
 * @date 2019-06-20 14:03
 * @since 1.0.0
 */
@Api(tags = {SwaggerTag.INNER_API + SwaggerTag.MEDICINE_REMIND + SwaggerTag.FOLLOW_UP})
@Validated
@RestController
@RequestMapping("recommend/inner/assist")
public class InnerAssistController {

    public static final Logger LOGGER = LoggerFactory.getLogger(InnerAssistController.class);

    private final IAssistService assistService;

    public InnerAssistController(IAssistService assistService) {
        this.assistService = assistService;
    }

    /**
     * 购药订单妥投触发
     *
     * @return
     */

    @PostMapping("order/complete")
    public ResponseVO<Void> orderComplete(OrderParamVO orderParamVO) {
        LOGGER.info("购药订单妥投触发系统用药提醒，参数信息 {}", orderParamVO);
        this.assistService.orderComplete(orderParamVO);
        return PublicService.returnResponseVO(ExceptionCodes.SUCCESS);
    }

    /**
     * 患者用药提醒回调
     *
     * @param recomId
     *
     * @return
     */

    @PostMapping("remind")
    public ResponseVO<Void> remindCallback(Long recomId) throws BusinessException {
        LOGGER.info("患者用药提醒回调，recomId {}", recomId);
        this.assistService.remindCallBack(recomId);
        return PublicService.returnResponseVO(ExceptionCodes.SUCCESS);
    }

    /**
     * 随访提醒回调
     *
     *
     * @return
     */

    @PostMapping("revisit")
    public ResponseVO<Void> revisitCallback() {
        LOGGER.info("随访提醒回调");
        this.assistService.revisitCallBack();
        return PublicService.returnResponseVO(ExceptionCodes.SUCCESS);
    }

    @GetMapping("drugremind")
    @ApiOperation(value = "处方助手-用药提醒设置信息", notes = "用药提醒设置信息", httpMethod = "GET")
    @ApiImplicitParams({@ApiImplicitParam(name = "recomId", value = "处方ID", required = true, dataType = "long", paramType = "query")})
    public ResponseVO<DrugRemindBO> drugRemind(Long recomId) {
        DrugRemindVO drugRemindVO = assistService.drugRemind(recomId);
        DrugRemindBO drugRemindBO = DrugRemindBO.builder().build();
        BeanUtil.copyProperties(drugRemindVO, drugRemindBO);
        return PublicService.returnResponseVO(drugRemindBO);
    }

    @GetMapping("getEnabledDrugremind")
    @ApiImplicitParam(name = "recomId", value = "处方ID", required = true, dataType = "long", paramType = "query")
    public Boolean getEnabledDrugremind(@RequestParam("recomId") Long recomId) {
        return this.assistService.getEnabledDrugremind(recomId);
    }

}
